<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
/*
Route::middleware('auth:api')->get('/user', function (Request $request) {
    return 'sss';
});
*/
//Route::group(['prefix' => 'v1', 'namespace'=>"Api\V1", 'middleware' => ['cors'], 'as' => 'api.v1.'], function () {
Route::group(['prefix' => 'v1', 'namespace'=>"Api\V1", 'as' => 'api.v1.'], function () {
    // 注册
    Route::post('register', 'RegisterController@register')->name('register');
    Route::post('register/sendsms', 'RegisterController@sendsms')->name('register.sendsms');

    // 登录
    Route::post('login', 'LoginController@login')->name('login');

    // 版本号
    Route::get('version', 'VersionController@index')->name('version');

    //统计
    Route::get('historyCount', 'DataScreenController@historyCount');
    Route::get('top15', 'DataScreenController@top15');
    Route::get('agencyStudentNum', 'DataScreenController@agencyStudentNum');
    Route::get('studentNum', 'DataScreenController@studentNum');
    Route::get('categoryNum', 'DataScreenController@categoryNum');
    Route::get('historyNum', 'DataScreenController@historyNum');
    Route::get('behavior', 'DataScreenController@behavior');
    // 设备注册
    Route::get('device/verify', 'DeviceController@verify')->name('device.verify');
    Route::post('device/register', 'DeviceController@register')->name('device.register');

    // 更改密码
    Route::post('reset/sendsms', 'ResetController@sendsms')->name('reset_sendsms');
    Route::post('reset/password', 'ResetController@password')->name('reset_password');

    // 需要权限验证
    Route::group(['middleware' => ['jwt.auth']], function () {
    //Route::group(['middleware' => ['auth:api']], function () {
        // Route::group(['middleware' => ['auth:api']], function () {
        // Token刷新
        Route::post('refresh', 'LoginController@refresh')->name('refresh');

        // 更改密码
        //Route::post('reset/password', 'ResetController@password')->name('reset_password');

        // 退出
        Route::post('logout', 'LoginController@logout')->name('logout');

        Route::post('child/add', 'ChildController@add');

        Route::get('child/star', 'ChildController@star');

        Route::post('game/start', 'GameController@start')->name('start');

        Route::post('game/finish', 'GameController@finish')->name('finish');

        Route::post('image/store', 'ImageController@store')->name('image.store');

        Route::post('currentchild', 'CurrentChildController@index')->name('currentchild');
        // 教师信息
        Route::match(['get', 'post'],'user', 'UserController@index');
        //学生列表
        Route::get('child/list', 'ChildController@index');

        // 个人中心
        Route::get('center', 'UserController@center')->name('center');
        // 个人中心
        Route::post('index', 'UserController@index')->name('home');
    });
});

Route::group(['prefix'=>'open', 'namespace'=>"Api\Openapi", 'as'=>"api.openapi."], function (){
    Route::get('image', 'ImageController@index');
    Route::get('historyCount', 'DataScreenController@historyCount');
    Route::get('top15', 'DataScreenController@top15');
    Route::get('agencyStudentNum', 'DataScreenController@agencyStudentNum');
    Route::get('studentNum', 'DataScreenController@studentNum');
    Route::get('categoryNum', 'DataScreenController@categoryNum');
    Route::get('historyNum', 'DataScreenController@historyNum');
    Route::post('alert', 'ImageController@alert');
});

//小程序部分接口，通过微信openid来验证
Route::group(['prefix' => 'wechat', 'namespace'=>"Api\Wechat", 'as' => 'api.wechat.'], function () {

    // 注册
    Route::post('register', 'RegisterController@register')->name('register');

    // 登录
    Route::post('login', 'LoginController@login')->name('login');


    // 需要权限验证
    Route::group(['middleware' => ['jwt.auth']], function () {

    //Route::group(['middleware' => ['auth:api']], function () {
        // Token刷新
        Route::post('refresh', 'LoginController@refresh')->name('refresh');

        //个人中心
        Route::get('user', 'UserController@index')->name("user");

        //用户管理孩子列表
        Route::get('child','ChildController@index');
        //查看孩子信息
        Route::get('childinfo/{id}','ChildController@view');
        //编辑孩子信息
        Route::post('childedit/{id}','ChildController@edit');
        //添加孩子信息
        Route::post('childadd','ChildController@add');
        //删除孩子信息
        Route::get('childdelete/{id}','ChildController@delete');


        //孩子训练记录
        Route::get('history/{id}','HistoryController@index')->name("history");
        //孩子训练明细
        Route::get('history/view/{id}','HistoryController@view')->name("history.view");

        // 退出
        Route::post('logout', 'LoginController@logout')->name('logout');

        Route::post('game/start', 'GameController@start')->name('start');

        Route::post('game/finish', 'GameController@finish')->name('finish');

        // 个人中心
        Route::get('center', 'UserController@center')->name('center');
        // 个人中心
        Route::post('index', 'UserController@index')->name('home');
    });
});
